<?php
/**
 * Created by PhpStorm.
 * User: dungnt13
 * Date: 11/26/14
 * Time: 10:35 AM
 */

namespace Frontend;

use BaseController,
    Input,
    Jinput,
    Str,
    View,
    Redirect,
    Validator,
    Singer,
    Response;

class SingersController extends BaseController
{
    public function getSuggestion()
    {
        $singers = Singer::where('type', '=', 'singer')->select('id', 'name')->get();
        $array = array();
        foreach ($singers as $singer)
            $array[$singer->id] = $singer->name;
        return Response::json($array);
    }

    public function postSuggestionSinger()
    {
        $name = Input::get('name');
        $singers = Singer::where('type', '=', 'singer')->where('name', 'LIKE', '%' . $name . '%')->select('id', 'name')->get();
        $array = array();
        foreach ($singers as $singer)
            $array['suggestions'][] = array('data' => $singer->id, 'value' => $singer->name);
        return Response::json($array);
    }

    public function postSuggestionMusician()
    {
        $name = Jinput::get('name');
        $singers = Singer::where('type', '=', 'musician')->where('name', 'LIKE', '%' . $name . '%')->select('id', 'name')->get();
        $array = array();
        foreach ($singers as $singer)
            $array['suggestions'][] = array('data' => $singer->id, 'value' => $singer->name);
        return Response::json($array);
    }
} 